import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import com.example.android.NewPage;
import com.example.android.Picture;
import com.example.android.R;

public class MainActivity extends AppCompatActivity implements View.OnClickListener  {
    //定义app状态(0 ,1 ,2 分别表示正常状态，从后台回到前台，从前台回到后台)
    private  static  int Appstate = 0;
    //是否进入前台
    private boolean Reception ;
    //是否进入后台
    private boolean backstage ;
    //定义按钮和标题
    private Button Btn01;
    private Button Btn02;
    private Button Btn03;
    private Button Btn04;
    private TextView Title;

//    private AlertDialog dialog02;
//    private AlertDialog.Builder builder02;
    private AlertDialog dialog = null;
    private  AlertDialog.Builder builder = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        BaseApplication one = new BaseApplication ();
        one.OneLastTime ();
        //设置全屏
        //getWindow().setFlags(Window.LayoutParam.FLAG_FULLSCREEN);
        //加入布局
        setContentView(R.layout.buju);
        Title = (TextView)findViewById(R.id.MainTitle);
        Btn01 = (Button)findViewById(R.id.Btn01);
        Btn01.setOnClickListener(this);
        Btn02 = (Button)findViewById(R.id.Btn02);
        //设置点击监听
        Btn02.setOnClickListener(this);
        Btn03 = (Button)findViewById(R.id.Btn03);
        Btn03.setOnClickListener(this);
        Btn04 = (Button)findViewById(R.id.Btn04);
        Btn04.setOnClickListener(this);
        Runnable mRunnable = new Runnable() {
            @Override
            public void run() {
                Toast.makeText(MainActivity.this, getString(R.string.string02), Toast.LENGTH_SHORT).show();
            }
        };
        mRunnable.run();
        Log.v("MainActivity","toast销毁");
    }
//    public static void startActivity(Context context){
//        builder02 = new AlertDialog.Builder(this);
//        dialog02 = builder.setIcon(R.drawable.ic_launcher_foreground) //设置图标
//                .setTitle("提示")//设置标题
//                .setMessage("欢迎来到主界面")//设置弹窗文本内容
//                //设置确定按钮
//                .setPositiveButton("确定", new DialogInterface.OnClickListener() {
//                    @Override
//                    public void onClick(DialogInterface dialogInterface, int i) {
//                        Toast.makeText(MainActivity.this, "您点击了确认按钮，进入主界面", Toast.LENGTH_SHORT).show();
//                    }}).create();
//
//        dialog02.show();
//
//    }



    @Override
    public void onClick(View view) {
        final int[] flag = new int[]{0};
        switch (view.getId()) {
            case R.id.Btn01:
                Btn01.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {

                        if(flag[0] == 0){
                            Btn01.setBackgroundColor(Color.DKGRAY);
                            flag[0] = 1;
                        }
                        else if(flag[0] ==1){
                            Btn01.setBackgroundColor(Color.GREEN);
                            flag[0] = 2;
                        }
                        else{
                            Btn01.setBackgroundColor(Color.RED);
                            flag[0] = 0;
                        }
                    }
                });
                break;

            case R.id.Btn02:
                Intent PictureTest = new Intent(MainActivity.this, Picture.class);
                startActivity(PictureTest);
                break;

            case R.id.Btn03:
                Intent Newpage = new Intent(MainActivity.this, NewPage.class);
                startActivity(Newpage);
                break;

            case R.id.Btn04:

                builder = new AlertDialog.Builder(this);
                dialog = builder.setIcon(R.drawable.ic_launcher_foreground) //设置图标
                        .setTitle(getString(R.string.string01))//设置标题
                        .setMessage(getString(R.string.string02))//设置弹窗文本内容
                        //设置确定按钮
                        .setPositiveButton(getString(R.string.dui), new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {
                                Toast.makeText(MainActivity.this, getString(R.string.string03), Toast.LENGTH_SHORT).show();
                            }
                        }).setNegativeButton(getString(R.string.cuo), new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {
                                Toast.makeText(MainActivity.this, getString(R.string.string04), Toast.LENGTH_SHORT).show();
                            }
                        }).create();
                dialog.show();
                break;

        }
    }
}
